import subprocess
import os
import sys
from time import sleep

def run_backend():
    backend_dir = os.path.join(os.path.dirname(__file__), 'backend')
    return subprocess.Popen([sys.executable, "scripts/start.py"], cwd=backend_dir)

def run_frontend():
    frontend_dir = os.path.join(os.path.dirname(__file__), 'frontend')
    return subprocess.Popen(["npm", "run", "dev"], cwd=frontend_dir)

if __name__ == "__main__":
    print("Starting backend server...")
    backend_process = run_backend()
    sleep(2)  # 等待后端启动
    
    print("Starting frontend development server...")
    frontend_process = run_frontend()
    
    try:
        backend_process.wait()
        frontend_process.wait()
    except KeyboardInterrupt:
        print("\nShutting down servers...")
        backend_process.terminate()
        frontend_process.terminate()
        backend_process.wait()
        frontend_process.wait()
        print("Servers stopped") 